'''
Created on Apr 27, 2016

@author: JimmyMo
'''
from dispatchtarget_rabbitmq import DispatchTarget_RabbitMQ
from dispatchmethod_timer import DispatchMethod_Timer
import threading

class DispatcherMibRefresher(threading.Thread):
    def __init__(self, config_reader):
        super(DispatcherMibRefresher, self).__init__()
        self.config_reader = config_reader
    def run(self):
        self.dispatch()
    def dispatch(self):
        interval = int(self.config_reader.items["MibRefresher"]["Interval"])
        queue_name = self.config_reader.items["MibRefresher"]["QueueName"]
        routing_key = self.config_reader.items["MibRefresher"]["RoutingKey"]
        rabbitmq_host = self.config_reader.items["General"]["RabbitMQHost"]
        
        target = DispatchTarget_RabbitMQ(host=rabbitmq_host, queue_name=queue_name, routing_key=routing_key)
        method = DispatchMethod_Timer(interval)
        
        method.set_method_target(target)
        method.dispatch()